/**$Licence:
 *  Copyright (C) 2008 - 2012 www.java1995.com . All rights reserved.
 *
 *  Use this however/wherever you like, just don't blame me if it breaks anything.
 *
 */

package com.blazemina.config;

import java.net.URL;

import com.blazemina.mina.handler.ServerHandler;

/**
 * 统一管理blazemina配置信息
 * @author JackChu
 * @version 1.0.0 2012-1-11 下午9:05:42
 */
public class BlazeminaConfigManager {
	
	private static final BlazeminaConfigManager configManager = new BlazeminaConfigManager();
	
	/**
	 * 配置文件
	 */
	private static final String CONFIG_FILE = "blazemina-config.xml";
	
	private BlazeminaConfigManager(){
		
	}
	
	public static BlazeminaConfigManager getManager(){
		return configManager;
	}
	
	private BlazeminaConfig blazeminaConfig;

	/**
	 * blazeminaConfig
	 *
	 * @return  the blazeminaConfig
	 */
	
	public BlazeminaConfig getBlazeminaConfig() {
		return blazeminaConfig;
	}

	/**
	 * blazeminaConfig
	 *
	 * @param   blazeminaConfig    the blazeminaConfig to set
	 */
	
	public void setBlazeminaConfig(BlazeminaConfig blazeminaConfig) {
		blazeminaConfig.throwIfConfigured();
		this.blazeminaConfig = blazeminaConfig;
	}
	
	/**
	 * 配置文件初始化
	 */
	public void init(){
		initBlazeminaConfig(CONFIG_FILE);
	}
	
	/**
	 * 初始化BlazeminaConfig
	 */
	private void initBlazeminaConfig(String configPath) {
		XMLConfig config = new XMLConfig();
		config.initDegister();
		URL url = BlazeminaConfigManager.class.getClassLoader().getResource(configPath);
		blazeminaConfig = config.parse(url);
		setBlazeminaConfig(blazeminaConfig);
		blazeminaConfig.freeze();
	}
	
	

}
